package priv.hxm.myutils;


import org.apache.log4j.Logger;

public class Stringuutil {
	private static Logger logger = Logger.getLogger(Stringuutil.class);

	/*
	 * 方法名到字段(只能是get,set)
	 */
	public static String method2FieldName(String methoedName) {
		if (!(methoedName.startsWith("get")) || methoedName.startsWith("set"))
			;
		String substring = methoedName.substring(3);
		String lowerCase = substring.substring(0, 1).toLowerCase();
		return lowerCase + substring.substring(1);
	}

	/*
	 * 字段名转get方法
	 */
	public static String String2GetName(String methoedName) {
		String lowerCase = methoedName.substring(0, 1).toUpperCase();
		return "get" + lowerCase + methoedName.substring(1);
	}

	/*
	 * 字段名转set方法
	 */
	public static String String2SetName(String methoedName) {
		String lowerCase = methoedName.substring(0, 1).toUpperCase();
		return "set" + lowerCase + methoedName.substring(1);
	}

	/*
	 * 驼峰命名转下划线
	 */
	public static String cape2underline(String name) {
		StringBuilder stringBuilder = new StringBuilder();
		for (int i = 0; i < name.length(); i++) {
			char charAt = name.charAt(i);
			if (charAt >= 65 && charAt <= 90) {
				if (i != 0)
					stringBuilder.append('_');
				stringBuilder.append((char) (charAt + 32));
			} else {
				stringBuilder.append(charAt);
			}
		}
		return stringBuilder.toString();

	}

}
